package com.ws.mbp.springsecuritydemo.controller;

import com.ws.mbp.springsecuritydemo.bean.Student;
import com.ws.mbp.springsecuritydemo.bean.Users;
import com.ws.mbp.springsecuritydemo.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/student")
@SecurityRequirement(name = "bearerAuth") // 添加这一行，表示该 Controller 需要 bearer token  配置 Swagger（Springdoc）支持 Authorization 请求头的输入和传递。
@Tag(name = "学生接口", description = "学生接口")
public class SecurityStudentAction {
    /**
     * 给 Controller 或接口添加 @SecurityRequirement(name = "bearerAuth")
     * 配置 springdoc.security.schemes.bearerAuth 支持 Bearer 模式
     * 在 Swagger UI 上点击 Authorize 输入 Bearer your_token
     * 即可正常测试受保护的接口
     * @param name
     * @param age
     * @return
     */
    @Operation(summary = "学生添加接口")
    @GetMapping("/add")
    @SecurityRequirement(name = "bearerAuth")
    public R add(@Parameter(description = "学生姓名",required = true) String name, @Parameter(description = "学生年龄",required = false) String age) {
        System.out.println("增加学生方法。。。。。。。。。。"+name+age);
        return new R(200, "增加学生成功", null);
    }
    @Operation(summary = "学生删除接口")   //参数@ApiParam ---- @Parameter
    @GetMapping("/delete/{id}")
    public R delete(@Parameter(description = "学生ID",required = true) @PathVariable Integer id) {
        System.out.println("删除学生方法。。。。。。。。。。"+id);
        return new R(200, "删除学生成功", null);
    }
    @Operation(summary = "学生更新接口")
    @PostMapping("/update")
    public R update(@RequestBody Student student) {
        System.out.println("修改学生方法。。。。。。。。。。"+student);
        return new R(200, "修改学生成功", null);
    }
    @Operation(summary = "学生更新接口2")
    @PutMapping("/update2")
    public R update2(@RequestBody Student student) {
        System.out.println("修改学生方法2。。。。。。。。。。"+student);
        return new R(200, "修改学生成功", null);
    }
    @GetMapping("/list")
    public R list() {
        System.out.println("查询学生方法。。。。。。。。。。");
        return new R(200, "查询学生成功", null);
    }


}